// 路由守卫文件
import router from "./router";
import { getCookie } from "@/utils/support.js";

// 将放行的白名单路由放到List中
const whiteList = ["/login"];

router.beforeEach((to, from, next) => {
    console.log("路由守卫触发");
    if (getCookie("token")) {
        if (to.path == "/login") {
            next("/");
        } else {
            next();
        }
    } else {
        // 没有登录
        if (whiteList.indexOf(to.path) != -1) {
            next();
        } else {
            next("/login");
        }
    }
});
